<!--MachineryTypeInput-->
<template>
  <div>
    <el-form :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

        <el-form-item label="检测编码" prop="ProjectCode">
          <el-input v-model="model.ProjectCode"></el-input>
        </el-form-item>

        <el-form-item label="检测名称" prop="ProjectName">
          <el-input v-model="model.ProjectName"></el-input>
        </el-form-item>

        <el-form-item label="分类" prop="Classify">
          <el-input v-model="model.Classify"></el-input>
        </el-form-item>
          
        <el-form-item label="父级分类" prop="ParentTypeName">
          <el-input v-model="model.ParentTypeName" :readonly="true" @focus="dialogVisible = true"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>

    </el-form>

    <!--弹窗-->
    <el-dialog append-to-body :close-on-click-modal="false" title="选择父级" :visible.sync="dialogVisible"  width="80%" >
      <SelecteQcProjectClassifyInput   @callback="callback" v-if="dialogVisible" />
    </el-dialog>


  </div>
</template>

<script>

import SelecteQcProjectClassifyInput from './SelecteQcProjectClassifyInput.vue';
export default {
  components:{
    SelecteQcProjectClassifyInput
  },
  props:{
    model:{
      require:true,
      type:Object
    },
    isUpdate:{
      require:true,
      type:Boolean,

    }
  },
  data(){
    return{
      dialogVisible:false,

      rules:{
        ProjectCode: {required: true, message: '请输入检测编码', trigger: 'blur'},
        ProjectName: {required: true, message: '请输入检测名称', trigger: 'blur'},
        Classify: {required: true, message: '请输入分类', trigger: 'blur'},
      }
    }
  },
  methods:{
    submitForm() {
      this.$refs['ruleForm'].validate((valid) => {
        if(valid){
          if(this.isUpdate){
            this.put();
          }else{
            this.add();
          }
        }else{
          this.showNotify('请输入必填项');
          return false;
        }
      });
    },
    resetForm(){
      this.$refs['ruleForm'].resetFields();
    },
    add(){

      this.$http.postForm('/api/QcProjectClassify',{model:this.model},{loading:this.$loading()})
      .then(()=>{
        this.$emit('callback');
        this.showNotify('新增检测项目成功');
      })
    },
    put(){
        this.$http.putForm('/api/QcProjectClassify',{model:this.model},{loading:this.$loading()})
        .then(()=>{
          this.$emit('callback');
          this.showNotify('修改检测项目成功');
        })
    },
    callback(model){
      //设置父级
      this.model.ParentClassify = model.Id;
      this.model.ParentTypeName=model.ProjectName;

      this.dialogVisible =false;
    }

  }
}

</script>

<style>

</style>